﻿#ifndef __AF_EFFECT_H__
#define __AF_EFFECT_H__

#include "AF_Define.h"

namespace AF
{
	//class Graphics -* ForEach
	//class Animation
		class Effect;
}
typedef AF::Effect			AF_CEffect;

#include "AF_Graphics.h"
#include "AF_Animation.h"
#include "AF_Package.h"

#define AF_EFFECT_START_ID		0
#define AF_EFFECT_END_ID		-1

#define AF_PRM_EFFECT_START_i		"EFFECT_START"
#define AF_PRM_EFFECT_END_i		"EFFECT_END"
#define AF_PRM_EFFECT_LOOP_b		"EFFECT_LOOP"
#define AF_PRM_EFFECT_REVERSE_b		"EFFECT_REVERSE"

namespace AF
{
	/// 特效类
	class _ABSTRACT Effect : public Graphics, public Animation
 	{
	private:
		enum ResKind
		{
			RK_UNKNOW,
			RK_PACKAGE,
			RK_IMAGE
		};

	public:
		Effect();
		virtual ~Effect();

	public:
		DIM_ATTRIB(int, Step);
		DIM_ATTRIB(bool, Reverse);
		DIM_ATTRIB_ASSOCIATED_R(int, Frame, m_nCurFm);

	public:
		/// 初始化
		bool			Init(Bundle* pParam = NULL);
		/// 初始化
		bool			Init(Package* pPackage, const UINT nStartID = AF_EFFECT_START_ID, const int nEndID = AF_EFFECT_END_ID, Bundle* pParam = NULL);
		/// 初始化
		bool			Init(Image* pImage, const UINT nWidthNum, const UINT nHeightNum, const UINT nFrameNum, Bundle* pParam = NULL);

	protected:
		virtual	bool		OnInit(AF_CBundle* pParam)
					{return true;}

	public:

		/// 播放当前状态
 		void			PlayNow();
		/// 播放到指定帧
		void			PlayTo(UINT nToFrame);
		/// 自由播放
		void			PlayFree(UINT nStartFrame, UINT nEndFrame, bool isLoop = false, bool isReverse = false);

		/// 重置
		bool			Reset(Package* pPackage, const UINT nStartID = AF_EFFECT_START_ID, const int nEndID = AF_EFFECT_END_ID);
		/// 重置
		bool			Reset(Image* pImage, const UINT nWidthNum, const UINT nHeightNum, const UINT nFrameNum);

		/// 设置当前帧
		void			SetFrame(UINT nFrameID);

		void			AddStep();

		/// 获得当前帧图像句柄
		ImageHandle		GetFrameImageHandle();
		/// 获得当前帧图像矩形
		Rect			GetClip();

	protected:
		bool			OnPlay(Bundle* pParam);
		bool			OnUpdate();

	private:
		bool			OnUpdateReverse();

		void			LoadPkgFrame(UINT nID);

	private:
		ResKind			m_ERK;
		ImageHandle		m_hFrame;
		Rect*			m_rClips;

		// ERK_Package
		Package*		m_pPackage;
		// ERK_Image
		ImageHandle		m_hImage;

	private:
		Bundle			m_Param;		// 播放传递参数

		int			m_nStartID;		// 动画开始位置
		int			m_nEndID;		// 动画结束位置

		int			m_nStartFm;		// 播放开始帧
		int			m_nEndFm;		// 播放结束帧
		int			m_nCurFm;		// 播放当前帧

 	};
}

#endif